package com.vcourse.service.statistics.task;

import com.vcourse.service.statistics.service.DailyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * @author Zengsh123
 * @date 2020-06-14 15:10
 */
@Slf4j
@Component
public class ScheduledTask {
    @Resource
    private DailyService dailyService;

    /**
     * 定时每天凌晨一点生成前一天的统计数据
     */
    @Scheduled(cron = "0 0 1 * * ?")
    public void taskGenarateStatisticsData(){
        String day = LocalDate.now().minusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        dailyService.createDailyData(day);
        log.info("taskGenarateStatisticsData 统计完毕");
    }
}
